#pragma once
#include <QWidget>
#include <QTimer>
#include <QPoint>
#include <QPixmap>
#include <QVector>

class PetWidget : public QWidget {
    Q_OBJECT
public:
    explicit PetWidget(QWidget *parent = nullptr);
    void moveToScreenCenter();
signals:
    void loadProgress(int progress);
    void loadFinished(bool success);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;

private slots:
    void updateAnimation();
    void resetToIdle();

private:
    enum class State { Idle, Clicked };

    State currentState = State::Idle;
    int currentFrame = 0;
    QPoint dragPosition;
    QTimer animationTimer;
    QVector<QPixmap> idleFrames;
    QVector<QSize> idleSizes;
    QVector<QPixmap> clickFrames;
    QVector<QSize> clickSizes;
    bool framesLoaded = false;

    void loadFrames();
    void initAnimationFrame(const QString &framePrefix, int frameCount, QVector<QPixmap> &frames, QVector<QSize> &sizes);
    void startLoadingFrames();

    void restrictToScreen(const QPoint &pos);
};
